﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ComplexNumbers
{
    public abstract class Complex
    {
         public abstract double Real { get; }

         public abstract double Imaginary { get; }

        public static Complex I
        {
            get
            {
                return new Descard(0, 1);
            }
        }

        public double this[int index]
        {
            get 
            {
                if (index < 0 || index > 1)
                {
                    throw new IndexOutOfRangeException();
                }

                if (index == 0)
                {
                    return Real;
                }
                else
                {
                    return Imaginary;
                }
            }
        }

        public static implicit operator Complex(double num)
        {
            return new Descard(num, 0);
        }

        public static explicit operator double(Complex num)
        {
            return num.Imaginary == 0 ? num.Real : num.Imaginary;
        }
    }
}
